#ifndef MPEG_PLAYER_H
#define MPEG_PLAYER_H

//gst-launch-1.0 -v filesrc location=smpl_vis.mp4 ! qtdemux ! nvmpeg4videodec ! cudaconvert ! cudadownload !
#include <gst/gst.h>
#include <gst/app/app.h>
#include <filesystem>
#include <thread>
#include <atomic>
#include <functional>

class MPEGPlayer
{
  public:
    MPEGPlayer();
    virtual ~MPEGPlayer();
    void Start(std::filesystem::path file,bool callbackMode);
    void Stop();
    std::function<void(const char* data,int width,int height)> funcNewImageCallback;
    std::function<void()> funcStopCallback; //发送停止信号
    //这个API吧，需要外部分配内存，然后内部会填充上去,也就是说这内存得1920*1080*3
    void GetNewImage(char* data); //block call
    bool GetPlayStatus();
private:
    GstElement *filesrc,*qtdemux,*nvmpeg4videodec,*cudaconvert,*cudadownload,*appsink;
    GstElement *pipeline;
    std::atomic_bool PlayFlag=false;
    friend void pad_added_handler (GstElement *src, GstPad *pad, MPEGPlayer *data);
    std::thread ReceiveDataThread;
};

#endif
